package p1290

import node.ListNode

/**
 * <pre>
 * 示例 1：
 *
 * 1-0-1
 *
 * 输入：head = [1,0,1]
 * 输出：5
 * 解释：二进制数 (101) 转化为十进制数 (5)
 * </pre>
 */
class ArrayListStragty : Stragty {
    override fun getDecimalValue(head: ListNode?): Int {
        var tempt: ListNode? = head
        var list: MutableList<Int> = mutableListOf()
        while (tempt != null) {
            list.add(tempt.`val`)
            tempt = tempt.next;
        }
        var sum: Int = 0
        var level: Int = 0;
        for (index in list.size - 1 downTo 0) {
            sum += list[index] * Math.pow(2.0, level * 1.0).toInt()
            level++;
        }
        return sum
    }
}